Fix draft per-request capability race in stateful sessions#1
Open
PranavSenthilnathan wants to merge 51 commits into
Open
Fix draft per-request capability race in stateful sessions#1PranavSenthilnathan wants to merge 51 commits into
PranavSenthilnathan wants to merge 51 commits into
Conversation
…l#1553) Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com> Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com> Co-authored-by: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…ode.InvalidParams` (-32602) per SEP-2164 (modelcontextprotocol#1558)
…elcontextprotocol#1590) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…otocol#1517) Co-authored-by: Jérémy Ballan <jballan@chapsvision.com> Co-authored-by: Tarek Mahmoud Sayed <10833894+tarekgh@users.noreply.github.com> Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…contextprotocol#1620) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…test (modelcontextprotocol#1627) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…odelcontextprotocol#1619) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…ldsNewlyWrittenEvents (modelcontextprotocol#1491)
…l server activity predicate (modelcontextprotocol#1495)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
modelcontextprotocol#1623) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…odelcontextprotocol#1568) Co-authored-by: Mike Kistler <mikekistler@microsoft.com>
… authorization (modelcontextprotocol#1591) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com>
…lcontextprotocol#1651) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
modelcontextprotocol#1644) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PranavSenthilnathan <12225508+PranavSenthilnathan@users.noreply.github.com> Co-authored-by: halter73 <54385+halter73@users.noreply.github.com> Co-authored-by: Pranav Senthilnathan <pranas@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Is and align `MCPEXP001` usage (modelcontextprotocol#1642)
…ogy, renumber error codes, ProtocolVersion floor (modelcontextprotocol#1671)
…results (SEP-2549 follow-up) (modelcontextprotocol#1669) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
Route client capability resolution through request-scoped DestinationBoundMcpServer state for 2026-07-28+ requests, stop persisting per-request capabilities into McpServerImpl global state, and add a concurrency regression test that verifies overlapping requests observe their own declared capabilities. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Gate DestinationBoundMcpServer.ClientInfo on the 2026-07-28+ protocol like ClientCapabilities so request handlers observe this request's declared client info rather than falling back to shared session state, which under a stateful transport could belong to a different concurrent request. Add a regression test verifying a tool observes the per-request client info. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…1686) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ontextprotocol#1687) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…otocol#1683) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
…change notifications (modelcontextprotocol#1689) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com> Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…col#1655) (modelcontextprotocol#1691) Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
…d coverage Source per-request client capabilities/info from JsonRpcMessageContext so outgoing message filters (built from responses) observe them, not just request handlers. Document that the shared client-info sync is best-effort for endpoint-name logging only, and clarify request-scoped semantics on McpServer.ClientCapabilities/ClientInfo. Pin UrlElicitationTests to the 2025-11-25 handshake revision for root-server capability assertions and add draft tests for request-scoped and outgoing-filter observation.
…fallback Remove the duplicate IsJuly2026OrLaterProtocolRequest in DestinationBoundMcpServer and route through a single internal overload on McpServerImpl. Clarify why the request-scoped ClientCapabilities fallback returns a fresh instance rather than a shared mutable singleton.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Draft protocol requests (SEP-2575) carry client capabilities per request in
_meta. The previous server path could read capability state from shared session fields, which allows concurrent requests to observe the wrong capabilities in stateful transports.What changed
DestinationBoundMcpServerto resolveClientCapabilitiesandClientInfofrom the current request context when available.DestinationBoundMcpServerinMcpServerImplso request-scoped metadata is available in handler/message-filter flows.McpServerImplshared_clientCapabilitiesstate from the meta-reading filter.nullcapabilities so unsupported server-to-client paths remain explicit,McpClientMetaTeststo verify overlapping tool calls with different declared capabilities each observe their own capability state.Notes for reviewers
The key non-obvious change is that per-request capabilities are now consumed only through request-scoped wrappers rather than persisted into shared server state. This is the core fix for the race described in modelcontextprotocol#1670.
Validation
dotnet builddotnet test tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj --filter "FullyQualifiedName~McpClientMetaTests"dotnet test tests/ModelContextProtocol.AspNetCore.Tests/ModelContextProtocol.AspNetCore.Tests.csproj --filter "FullyQualifiedName~StatelessServerTests"